package com.chujian.system.auth.controller;

import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.map.MapUtil;
import com.chujian.framework.component.YFuncParams;
import com.chujian.framework.component.YFuncParts;
import com.chujian.framework.component.def.YCol;
import com.chujian.framework.component.def.YEditCol;
import com.chujian.framework.component.def.YForm;
import com.chujian.framework.component.def.YQuery;
import com.chujian.core.entity.CoreDict;

import java.util.Arrays;

public class TestComponent {

    //  权限结果返回示例，遵循此结构返回即可
    public static YFuncParts creTestFuncParts() {
        return new YFuncParts()
                .setFuncKey("TestAuth")
                .setQueries(
                        MapBuilder.<String, YQuery>create()
                                .put("ddlQuery",
                                        new YQuery() // 字典主查询
                                                .setKey("ddlQuery")
                                                .setName("字典查询")
                                                .setTableName("")
                                                .setClazz(CoreDict.class.getName())
                                                .setQueryUrl("/system/coreDict/page")
                                                .setQueryParams(MapUtil.of("status", 1))
                                                .setQueryDataProp("data")
                                                .setQueryIdField("id")
                                                .setQueryTitleField("name")
                                                .setCols(
                                                        Arrays.asList(
                                                                new YCol()
                                                                        .setCol("dictPid")
                                                                        .setVisible(false),
                                                                new YCol()
                                                                        .setCol("dictRid")
                                                                        .setVisible(false)
                                                        )
                                                )
                                )
                                .put("menuTemplateQuery",
                                        new YQuery()
                                                .setKey("menuTemplateQuery")
                                                .setName("字典-菜单模板查询")
                                                .setQueryUrl("/system/coreDict/list")
                                                .setQueryParams(MapUtil.of("dictPid", 200))
                                )
                                .build()
                )
                .setForms(
                        MapBuilder.<String, YForm>create()
                                .put("edit-test",
                                        new YForm()
                                                .setName("字典新增修改")
                                                .setKey("edit-test")
                                                .setClazz(CoreDict.class.getName())
                                                .setCols(
                                                        // 设置权限
                                                        Arrays.asList(
                                                                new YEditCol("dictKid", "逻辑值")
                                                                        .setEditable(true)
                                                                        .setEnabled(true),
                                                                new YEditCol("dictName", "字典名")
                                                                        .setEditable(true)
                                                                        .setEnabled(true)
                                                        )
                                                )
                                )

                                .build()
                )
                // 操作
                .setOpers(
                        MapBuilder.<String, YFuncParams>create()
                                .put("insert", new YFuncParams().setEnabled(true))
                                .put("update", new YFuncParams().setEnabled(true))
                                .put("delete", new YFuncParams().setEnabled(true))
                                .build()
                )
                // 功能参数
                .setParams(
                        MapBuilder.<String, YFuncParams>create()
                                .put("authAprv", new YFuncParams().setName("自动审核").setEnabled(false))
                                .build()
                )
                ;
    }


}
